# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: andre.menrath@posteo.de

pkgname=sws
pkgver=2.13.2.0
pkgrel=1
pkgdesc='A collection of features that seamlessly integrate into REAPER'
arch=('loong64' 'x86_64')
url='https://www.sws-extension.org/'
license=('MIT')
depends=(
  'glibc'
  'gcc-libs'
  'reaper'
  'taglib'
)
makedepends=(
  'git'
  'cmake'
  'php'
  'perl'
  'gtk3'
)
install='sws.install'
_commit='a3693ad52ed16fe95ac0a570971656b6c9337f26'
source=(
  "git+https://github.com/reaper-oss/sws.git#commit=$_commit"
  'github.com-justinfrankel-wdl::git+https://github.com/justinfrankel/WDL'
  'github.com-justinfrankel-reaper-sdk::git+https://github.com/justinfrankel/reaper-sdk'
)
b2sums=('SKIP'
        'SKIP'
        'SKIP')

pkgver() {
  cd "$pkgname"

  head -n 1 version.h.in | cut -d ' ' -f 3 | tr , .
}

prepare() {
  cd "$pkgname"

  # prepare git submodule(s)
  # note: vendor/taglib submodule is skipped because we use system taglib
  git submodule init vendor/WDL vendor/reaper-sdk
  git config submodule.vendor/WDL.url "$srcdir/github.com-justinfrankel-wdl"
  git config submodule.vendor/reaper-sdk.url "$srcdir/github.com-justinfrankel-reaper-sdk"
  git -c protocol.file.allow=always submodule update vendor/WDL vendor/reaper-sdk
}

build() {
  cmake \
    -B build \
    -S "$pkgname" \
    -DCMAKE_BUILD_TYPE=Release \
    -DUSE_SYSTEM_TAGLIB=YES

  cmake --build build
}

package() {
  # plugin
  install -vDm755 -t "$pkgdir/usr/lib/sws" "build/reaper_sws-$CARCH.so"
  install -vDm644 -t "$pkgdir/usr/lib/sws" build/sws_python64.py

  cd "$pkgname"

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md whatsnew.txt

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" COPYING
}
